﻿using System;
namespace LeRenard.ScriptWars.Model.Scripting.OperationParameterTypeValueConverters
{
    /// <summary>
    /// Handles conversion from <see cref="OperationParameterType.Integer"/> to <see cref="int"/>.
    /// </summary>
    public sealed class IntegerParameterTypeValueConverter : OperationParameterTypeValueConverter<int>
    {
        /// <summary>
        /// Creates a new <see cref="IntegerParamaterTypeValueConverter"/> object.
        /// </summary>
        public IntegerParameterTypeValueConverter() : base(OperationParameterType.Integer) { }

        /// <summary>
        /// Converts the raw script value to a .Net type value.
        /// </summary>
        /// <param name="parameterValue">The value to be converted.</param>        
        public override int ConvertFromScriptValue(string parameterValue)
        {
            ThrowIf.NullOrEmpty(() => parameterValue);

            return Int32.Parse(parameterValue);
        }

        /// <summary>
        /// Converts a .Net type value to the raw script value.
        /// </summary>
        /// <param name="parameterValue">the value to be converted.</param>        
        public override string ConvertToScriptValue(int parameterValue)
        {
            return parameterValue.ToString();
        }
    }
}
